package com.djhu.newscollector.crawel.core;

import com.djhu.newscollector.core.entity.Request;
import com.djhu.newscollector.core.job.BaseJob;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by zw on 2018/2/11.
 */
public class Url  implements BaseJob {
    private String key = null;
    private String url = null;
    private long executeTime = System.currentTimeMillis();
    private String method = "GET";
    private int executeCount = 0;
    //附加信息
    private JSONObject metaData = new JSONObject();


    @Override
    public String id() {
        if (StringUtils.isNotEmpty(key)){
            return key;
        }
        if (url.endsWith("#")){
            return url.substring(0,url.length()-1);
        }
        return String.valueOf(url.toString().hashCode());
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public long getExecuteTime() {
        return executeTime;
    }

    public void setExecuteTime(long executeTime) {
        this.executeTime = executeTime;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public int getExecuteCount() {
        return executeCount;
    }

    public void setExecuteCount(int executeCount) {
        this.executeCount = executeCount;
    }

    public JSONObject getMetaData() {
        return metaData;
    }

    public void setMetaData(JSONObject metaData) {
        this.metaData = metaData;
    }

    public void addMetaData(String key,Object value){
        metaData.put(key,value);
    }

    @Override
    public String name() {
        return "news";
    }

    @Override
    public Integer priority() {
        return 1;
    }
}